<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!--  准备好一个容器  -->
    <div id="test1"></div>
    <div id="test2"></div>
    <div id="test3"></div>


    <!--  引入react核心库  -->
    <script type="text/javascript" src="../../js_base/react.development.js"></script>
    <script type="text/javascript" src="../../js_base/react-dom.development.js"></script>
    <script type="text/javascript" src="../../js_base/babel.min.js"></script>
    <!--  引入prop-types，用于对组件标签属性进行限制  -->
    <script type="text/javascript" src="../../js_base/prop-types.js"></script>

    <script type="text/babel">
        // 创建组件
        class Person extends React.Component {
            render() {
                return (
                    <ul>
                        <li>姓名：{this.props.name}</li>
                        <li>性别：{this.props.sex}</li>
                        <li>年龄：{this.props.age}</li>
                    </ul>
                )
            }

            static propTypes = {
                // 限制name属性接收字符串，且必须传入
                // 如果违反限制，页面仍会正常显示，但控制台报错
                name: PropTypes.string.isRequired,
                sex: PropTypes.string,
                age: PropTypes.number
            }

            static defaultProps = {
                sex: "男"
            }
        }

        // 渲染组件到页面
        ReactDOM.render(<Person name='tom' age={19} sex='男' />, document.getElementById("test1"))
        ReactDOM.render(<Person name='jerry' age={18} sex='女' />, document.getElementById("test2"))

        const p = { name: 'dog', age: 20, sex: '男' }
        ReactDOM.render(<Person {...p} />, document.getElementById("test3"))
    </script>

</body>

</html>